package com.houxiurong.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by houxiurong on 2017/8/2.
 */
public class NewMap {

    private final static Map statesAndCapitals;

    static {
        statesAndCapitals = new HashMap<>();
        statesAndCapitals.put("Alaska", "Anchorage");
        statesAndCapitals.put("California", "Sacramento");
        statesAndCapitals.put("Colorado", "Denver");
        statesAndCapitals.put("Florida", "Tallahassee");
        statesAndCapitals.put("Nevada", "Las Vegas");
        statesAndCapitals.put("New Mexico", "Sante Fe");
        statesAndCapitals.put("Utah", "Salt Lake City");
        statesAndCapitals.put("Wyoming", "Cheyenne");
    }


    public static void main(String[] args) {
        Object object = statesAndCapitals.getOrDefault("Alaska", "Unknown");
        System.out.println("object1:" + object);
        final Object capitalNewYork = statesAndCapitals.putIfAbsent("New York", "Albany");
        System.out.println("capitalNewYork:" + capitalNewYork);
        Object newyork = statesAndCapitals.getOrDefault("New York", "Unknown");
        System.out.println("new-capitalNewYork:" + newyork);

        final boolean removedJdk8 = statesAndCapitals.remove("California", "Sacramento");
        System.out.println("new-removedJdk8:" + removedJdk8);

        final int ss = statesAndCapitals.size();
        final boolean flag = statesAndCapitals.isEmpty();
        System.out.println(ss);
        System.out.println(flag);

        System.out.println("front:" + statesAndCapitals.get("Alaska"));
        final Object replacedJdk8City = statesAndCapitals.replace("Alaska", "Juneau");
        System.out.println("end:" + statesAndCapitals.get("Alaska"));

        // JDK8的实现方式
        final boolean replacedJdk8 = statesAndCapitals.replace("Nevada", "Las Vegas", "hangzhou");
        System.out.println("replacedJdk8===="+replacedJdk8);
        System.out.println("replace end:" + statesAndCapitals.get("Nevada"));
    }
}
